#ifndef _DAEMON_H_
#define _DAEMON_H_

#include <QObject>
#include <QTimer>

#include "file.h"
#include "folder.h"
#include "daemonerror.h"
#include "sendererror.h"
#include "fileerror.h"


class QString;
class QNetworkAccessManager;

namespace Avd {

class Config;
class Disk;
class Sender;
class Receiver;
class FileSystemWatcher;

class Daemon: public QObject {
Q_OBJECT
public:

	Daemon(const QString& configFileName) throw(DaemonError);
	~Daemon();

	void askLogin() throw(SenderError);
	void askLogoff() throw(SenderError);
	void askDownload(const File& file) throw(SenderError);
	void askUpload(File& file) throw(FileError, SenderError);
	void askList(const Folder& folder) throw(SenderError);
	void askMove(const QString& oldPath, const QString& oldName,
							 const QString& newPath, const QString& newName) throw(SenderError);
	void askDelete(const File& file) throw(SenderError);
	void askDelete(const Folder& folder) throw(SenderError);
	void askCreateFolder(const Folder& folder) throw(SenderError);
	void askCopy(const File& file, const Folder& copyFolder) throw(SenderError);
	void askCopy(const Folder& folder, const Folder& copyFolder) throw(SenderError);
	void askVersion(const QString& path, const QString& name) throw(SenderError);

	bool connected() const;
	Disk* getDisk() { return disk; }

public slots:
	void slotLogin(unsigned int status, unsigned int session);
	void slotLogoff(unsigned int status);
	void slotDownload(unsigned int status, File& file,
										const unsigned int part = 0, const unsigned int totalParts = 1);
	void slotUpload(unsigned int status, File& file);
	void slotList(unsigned int status, const QString& path,
								QList<File> files, QList<Folder> folders);
	void slotDelete(unsigned int status, QString& fullPath);
	void slotVersion(unsigned int status, const File& file);
	void slotCopy(unsigned int status, QString path, const File& file);
	void slotCreateFolder(unsigned int status, const Folder& folder);
	void slotMove(unsigned int status, const QString& oldPath, const QString& newPath);

	void updateDisk();

signals:

private:
	FileSystemWatcher* fs;
	QString configFileName;
	Config *config;
	Disk *disk;
	Sender *sender;
	Receiver *receiver;
	QTimer *timer;
	bool isConnected;
	unsigned int session;
};

}

#endif

